package io.File;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo1 {
    public static void main(String[] args) throws IOException {
        FileInputStream inputStream = new FileInputStream("D:\\test\\a.java");
        FileOutputStream outputStream = new FileOutputStream("D:\\test\\b.java", true);
        long start =  System.currentTimeMillis();//当前时间
        int read;
        do {
            //读
            read =inputStream.read();
            //写
            outputStream.write(read);
        }while (read!=-1);
        long end =System.currentTimeMillis();
        System.out.println(end-start);//记时
        outputStream.close();
        inputStream.close();
    }

    private static void test2() throws IOException {
        FileInputStream inputStream = new FileInputStream("D:\\test\\a.java");
        FileOutputStream outputStream = new FileOutputStream("D:\\test\\b.java", true);
        long start =  System.currentTimeMillis();//当前时间
        byte[] buff = new byte[300];
        int len =-1;
        do {
            len = inputStream.read(buff);
            if (len>=0){
                outputStream.write(buff,0,len);
            }
        }while (len!=-1);
        long end =System.currentTimeMillis();
        System.out.println(end-start);
    }

    private static void test1() throws IOException {
        FileInputStream inputStream = new FileInputStream("D:\\test\\a.java");
        FileOutputStream outputStream = new FileOutputStream("D:\\test\\b.java", true);
        int len = -1;
        byte[] buff = new byte[1024];
        while ((len = inputStream.read(buff)) != -1) {
            outputStream.write(buff);
        }
        inputStream.close();
        outputStream.close();
    }
}
